package com.shzu.jwc.ty.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.bean.ProblemClass;
import com.shzu.jwc.ty.bean.ProblemClassExample;
import com.shzu.jwc.ty.bean.ProblemClassExample.Criteria;
import com.shzu.jwc.ty.dao.ProblemClassMapper;

@Service
public class ProblemClassService {

	@Autowired
	ProblemClassMapper problemClassMapper;
	public List<ProblemClass> getproblemclass()
	{
		return problemClassMapper.selectByExample(null);
	}
	
	public Integer updatepro(Integer id,String column,String value)
	{
		ProblemClass problemClass=problemClassMapper.selectByPrimaryKey(id);
		if(column.equals("problemClassName"))
			problemClass.setProblemClassName(value);
		if(column.equals("problemClassValue"))
			problemClass.setProblemClassValue(Integer.parseInt(value));
		return problemClassMapper.updateByPrimaryKey(problemClass);
	}
	
	public Integer add(ProblemClass problemClass)
	{
		return problemClassMapper.insert(problemClass);
	}
	
	public Integer delete(Integer id)
	{
		return problemClassMapper.deleteByPrimaryKey(id);
	}
	
	public Integer valuegetid(String value)
	{
		ProblemClassExample problemClassExample=new ProblemClassExample();
		Criteria criterion=problemClassExample.createCriteria();
		criterion.andProblemClassNameEqualTo(value);
		List<ProblemClass> data=problemClassMapper.selectByExample(problemClassExample);
		if(data.size()==0)
			return 404;
		else
			return data.get(0).getProblemClassId();
	}
}
